package cn.xiuxius.embedded.command.converter;

import picocli.CommandLine.ITypeConverter;
import picocli.CommandLine.TypeConversionException;

import java.io.File;

public class ExistingFileConverter implements ITypeConverter<File> {
    @Override
    public File convert(String value) {
        File file = new File(value);
        if (!file.exists() || !file.isFile()) {
            throw new TypeConversionException("File does not exist: " + value);
        }
        return file;
    }
}
